package com.hjqjl.whdemo.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.hjqjl.whdemo.R;

public class GlideUtils {
    public static void loadNotPlace(Context context, ImageView imageView, String url) {
        if (TextUtils.isEmpty(url)) {
            imageView.setImageResource(R.drawable.ic_image_default);
            return;
        }

        Glide.with(context)
                .load(url)
                .placeholder(R.drawable.ic_image_default)
                .error(R.drawable.ic_image_default)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
    }

    public static void loadNotPlaceNoDefault(Context context, ImageView imageView, String url) {
        if (TextUtils.isEmpty(url)) {
            imageView.setImageResource(R.drawable.ic_image_default);
            return;
        }
        Glide.with(context)
                .load(url)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);

    }

    public static void loadPlace(Context context, ImageView imageView, String url, int placeHolderID) {
        if (TextUtils.isEmpty(url)) {
            imageView.setImageResource(R.drawable.ic_image_default);
            return;
        }
        Glide.with(context)
                .load(url)
                .placeholder(placeHolderID)//加载中图片
                .error(placeHolderID)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
    }

    public static void loadImgNoCache(Context context, int res, ImageView imageView) {
        Glide.with(context)
                .load(res)
                .skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
    }
}
